﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace Eleanor.Website.Utility
{
    public class PikaQResult : JsonResult
    {
        JsonResult originalResult;

        public PikaQResult(JsonResult originalResult)
        {
            this.originalResult = originalResult;
            actionCode = PikaQActionCode.Do;
        }

        private string actionCode;
        public string ActionCode
        {
            get
            {
                if (string.IsNullOrWhiteSpace(actionCode))
                {
                    return PikaQActionCode.Do;
                }
                return actionCode;
            }
            set { actionCode = value; }
        }
        public override void ExecuteResult(ControllerContext context)
        {
            dynamic responseData = new
            {
                actionCode = actionCode,
                actionData = originalResult.Data
            };
            context.HttpContext.Response.Write(JsonConvert.SerializeObject(responseData));
        }
    }


    public class PikaQActionCode
    {
        public static readonly string Do = "do";
        public static readonly string Redirect = "redirect";
        public static readonly string Login = "login";
        public static readonly string Error = "error";
    }
}